/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package objective;

/**
 *
 * @author daz
 */
public class AandBnotSameValueAtDifferentIndex implements IObjective {

    private int violateDegrees;
    private int[] setA;
    private int[] setB;

    public AandBnotSameValueAtDifferentIndex(int[] setA, int[] setB) {
        this.setA = setA;
        this.setB = setB;
        this.violateDegrees = calculateViolation(setA, setB);
    }

    private int calculateViolation(int[] setA, int[] setB) {
        int result = 0;
        for (int i = 0; i < setA.length; i++) {
            for (int j = 0; j < setA.length; j++) {
                if (i != j && setA[i] == setA[j] && setB[i] == setB[j]) {
                    result++;
                }
            }
        }
        return result;
    }

    @Override
    public int getAssignDelta(int index, int newValue) {
        if (index < setA.length) {
            setA[index] = newValue;
        } else {
            setB[index % setB.length] = newValue;
        }
        return calculateViolation(setA, setB) - violateDegrees;
    }

    @Override
    public int getViolateDegrees() {
        return this.violateDegrees;
    }
}
